<template>
	<view class="page-wrap">
		<navBar></navBar>
		<match-media :max-width="MAX_SIZEiZE - 1">
			<view class="tabbar">
				<tabBar :showselected="true"></tabBar>
			</view>
		</match-media>
		<view class="content">
			<view>
				<match-media v-if="smallScreen" :max-width="MAX_SIZEiZE - 1">
					<uni-nav-bar statusBar backgroundColor="var(--bg-3)" :border="false">
						<text class="page-title">{{ $t('Page.mine.title') }}</text>
					</uni-nav-bar>
				</match-media>
				<view class="user-info">
					<view class="user-info-cont">
						<waves class="avatar-wrap" @onTap="tapUserInfo">
							<image class="avatar" :src="userInfo.avatar"></image>
						</waves>
						<view class="id-info">
							<view>
								<text class="username">{{userInfo.username}}</text>
								<text class="vip-level">vip{{userInfo.level && userInfo.level.grade}}</text>
							</view>
							<text class="uid">ID.{{userInfo.id}}</text>
						</view>
					</view>
					<view class="wallet-wrap">
						<view class="wallet-entry" @click="toMyWallet">
							<view class="wallet-entry-l">
								<view class="wallet-text">
									{{ $t('Page.mine.myWallet') }}
								</view>
								<view class="money">
									R$ {{ userMoney }}
								</view>
							</view>
							<view class="wallet-entry-r">
								<image class="wallet-icon" :src="`/static/image/Mine/wallet-${theme}.png`"
									mode="aspectFit">
								</image>
							</view>
						</view>
						<match-media v-if="bigScreen" :min-width="MAX_SIZEiZE" class="VIP-entry">
							<view class="VIP-entry-l">
								<image class="crown" :src="`/static/image/Mine/crown-${theme}.png`" mode="aspectFit">
								</image>
								<text class="VIP-text">{{ $t('Page.mine.vipSpace') }}</text>
							</view>
							<text class="VIP-check" @click="goVipPage">{{ $t('Page.mine.check') }}</text>
						</match-media>
					</view>
				</view>
				<match-media v-if="smallScreen" :max-width="MAX_SIZEiZE" class="VIP-entry">
					<view class="VIP-entry-l">
						<image class="crown" :src="`/static/image/Mine/crown-${theme}.png`" mode="aspectFit"></image>
						<text class="VIP-text">{{ $t('Page.mine.vipSpace') }}</text>
					</view>
					<text class="VIP-check" @click="goVipPage">{{ $t('Page.mine.check') }}</text>
				</match-media>
				<view class="list-wrap">
					<view
						:class="['item',{'item-divide-bottom':item.isDivideBottom,'item-divide-top':item.isDivideTop}]"
						v-for="(item,index) in list" :key="index" @click="handleClick(item,index)">
						<image class="item-icon" :src="`/static/image/Mine/${item.icon}-${theme}.png`" mode="aspectFit">
						</image>
						<text class="item-text">{{item.text}}</text>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="logout" type="center" :is-mask-click="false">
			<view class="popup-cont">
				<view class="tips">
					{{ $t('Page.mine.tinmdarstlo') }}
				</view>
				<view class="btns">
					<waves class="btn cancel" @onTap="handlePopup('close')">
						{{ $t('Page.mine.cancel') }}
					</waves>
					<waves class="btn confirm" @onTap="logOut">
						{{ $t('Page.mine.confirm') }}
					</waves>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import {
		MAX_SIZEiZE
	} from '@/common/app.js'
	import {
		mapState,
		mapMutations,
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		sendMessage
	} from '@/api/websocket.js'
	export default {
		data() {
			return {
				MAX_SIZEiZE,
				list: [{
						icon: 'collect',
						text: this.$t('Page.mine.myCollection'),
						pagePath: "/pages/Mine/myCollect",
					},
					{
						icon: 'team',
						text: this.$t('Page.mine.myTeam'),
						pagePath: "/pages/Mine/myTeam",
					},
					{
						icon: 'recovery',
						text: this.$t('Page.mine.onclre'),
						pagePath: "/pages/tabBar/home/index",
						type: 'opt-recycle'
					},
					// {
					// 	icon: 'rebate',
					// 	text: 'One-click rebate',
					// 	pagePath: "/pages/tabBar/home/index",
					// 	isDivideTop: true
					// },
					{
						icon: 'wallet',
						text: this.$t('Page.mine.witinf'),
						pagePath: "/pages/Mine/bindBank",
						isDivideBottom: true
					},
					// {
					// 	icon: 'chat',
					// 	text: 'Chatroom',
					// 	pagePath: "/pages/tabBar/home/index",
					// },
					{
						icon: 'service',
						text: this.$t('Page.mine.gacuse'),
						pagePath: "/pages/tabBar/home/index",
						type: 'link'
					},
					{
						icon: 'logout',
						text: this.$t('Page.mine.logOut'),
						pagePath: "/pages/tabBar/home/index",
						isDivideTop: true,
						type: 'popup'
					},
					// {
					// 	icon: 'logoff',
					// 	text: 'Cancel Account',
					// 	pagePath: "/pages/tabBar/home/index",
					// 	isDivideBottom: true
					// }
				]
			}
		},
		computed: {
			...mapState({
				userInfo: state => state.app.userInfo,
				theme: state => state.app.theme,
				userMoney: state => state.app.userMoney || '0.00',
				liveSupport: state => state.app?.homeData?.customer_service?.LiveSupport
			}),
			...mapGetters('app', ['isLogin', 'bigScreen', 'smallScreen']),
		},
		onPullDownRefresh() {
			// 下拉刷新，请求用户信息
			this.getUserInfo();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			...mapMutations('app', ['saveActiveTab']),
			...mapActions('app', ['getRecycle', 'userLogout', 'getUserInfo']),
			tapUserInfo() {
				uni.navigateTo({
					url: '/pages/Mine/info/info'
				})
			},
			goVipPage() {
				uni.navigateTo({
					url: '/pages/Mine/vipSpace/vipSpace'
				})
			},
			toMyWallet() {
				uni.navigateTo({
					url: '/pages/Mine/wallet/wallet'
				})
			},
			handlePopup(flag) {
				this.$refs.logout[flag]('center')
			},
			logOut() {
				this.userLogout()
				this.handlePopup('close');
				this.saveActiveTab(0);
				uni.navigateTo({
					url: '/pages/auth/auth?type=0'
				})
			},
			handleClick(item, index) {
				if (item.type === 'popup') {
					this.handlePopup('open')
				} else if (item.type === 'link') {
					this.$tools.jumpLink(this.liveSupport)
				} else if (item.type === 'opt-recycle') { //一键回收 
					this.getRecycle()
				} else {
					uni.navigateTo({
						url: item.pagePath
					})
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	// 默认样式 结构  

	.page-wrap {
		min-height: 100vh;
		background: var(--bg-3);

		.content {
			width: 100%;
			min-height: calc(100vh - 50px);
			background: var(--bg-3);
			padding: 0 15px 65px;
			box-sizing: border-box;

			.page-title {
				width: 100%;
				margin: auto;
				height: 44px;
				line-height: 44px;
				font-size: 20px;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				text-align: center;
			}

			.user-info {
				width: 100%;
				display: flex;
				flex-direction: column;
				border-radius: 15px;
				margin-top: 10px;
				background: var(--bg-14);
				overflow: hidden;

				.user-info-cont {
					flex: 1;
					background: var(--bg-14);
					padding: 15px;
					display: flex;
					align-items: center;
					box-sizing: border-box;

					.avatar-wrap {
						width: 60px;
						height: 60px;
						display: flex;
						justify-content: center;
						align-items: center;
						border-radius: 50%;
						border: 2px solid var(--border-color-1);
						margin-right: 15px;

						.avatar {
							width: 56px;
							height: 56px;
							border-radius: 50%;
						}
					}


					.id-info {
						max-width: 190px;
						height: 60px;
						padding: 8px 0;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.username {
							font-size: 16px;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #FFFFFF;
							margin-right: 10px;
						}

						.vip-level {
							background: var(--bg-6);
							border-radius: 15px 15px 15px 15px;
							font-size: 10px;
							color: #FFFFFF;
							font-style: italic;
							text-shadow: 0px 2px 2px #B63712;
							margin-right: 116px;
							padding: 2px 10px 4px 8px;
						}

						.uid {
							font-size: 13px;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: var(--color-12);
							line-height: 15px;
							margin-top: 4px;
						}
					}
				}

				.wallet-wrap {
					display: flex;
					align-items: center;

					.wallet-entry {
						width: 100%;
						height: 60px;
						display: flex;
						justify-content: space-between;
						align-items: center;
						background: var(--bg-15);
						padding: 10px 10px 10px 15px;
						cursor: pointer;
						box-sizing: border-box;

						.wallet-entry-l {
							display: flex;
							flex-direction: column;
							color: #fff;

							.wallet-text {
								font-size: 13px;
								font-family: PingFang SC-Bold, PingFang SC;
								font-weight: bold;
								color: #FFFFFF;
							}

							.money {
								font-size: 15px;
								font-family: Inter-Bold, Inter;
								font-weight: bold;
							}

						}

						.wallet-entry-r {
							margin-left: auto;

							.wallet-icon {
								width: 40px;
								height: 40px;
							}
						}
					}
				}
			}

			.VIP-entry {
				width: 100%;
				height: 50px;
				display: flex;
				align-items: center;
				justify-content: space-between;
				align-items: center;
				background: var(--bg-16);
				padding: 10px 10px 15px;
				border-radius: 100px;
				margin-top: 15px;
				cursor: pointer;
				box-sizing: border-box;

				.VIP-entry-l {
					display: flex;
					align-items: center;

					.crown {
						width: 40px;
						height: 40px;
					}

					.VIP-text {
						font-size: 16px;
						font-weight: bold;
						color: var(--color-13);
						line-height: 19px;
						margin-left: 10px;
					}
				}

				.VIP-check {
					height: 30px;
					line-height: 30px;
					background: var(--bg-17);
					border-radius: 15px;
					padding: 0 10px;
					color: var(--color-white);
					font-size: 10px;
					box-shadow: inset 0px 4px 4px 0px var(--box-shadow-color-1);
				}
			}


			.list-wrap {
				margin-top: 15px;
				border-radius: 15px;
				border-radius: 15px;
				overflow: hidden;

				.item {
					height: 60px;
					display: flex;
					align-items: center;
					padding: 0 15px;
					background: var(--bg-9);
					cursor: pointer;
					box-sizing: border-box;

					&:hover {
						opacity: .65;
					}


					.item-icon {
						width: 35px;
						height: 35px;
					}

					.item-text {
						font-size: 15px;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #FFFFFF;
						margin-left: 15px;
					}

				}

				.item-divide-bottom {
					margin-top: 20px;
					border-radius: 15px 15px 0 0;
				}

				.item-divide-top {
					border-radius: 0 0 15px 15px;
				}
			}
		}
	}

	.popup-cont {
		width: calc(100vw - 60px);
		background: var(--bg-38);
		opacity: .95;
		border-radius: 15px;
		padding: 30px;
		box-sizing: border-box;
		opacity: 0.95;
		display: flex;
		align-items: center;
		flex-direction: column;

		.tips {
			height: 48px;
			line-height: 48px;
			font-size: 17px;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: rgba(255, 255, 255, 0.9);
			line-height: 24px;
		}

		.btns {
			display: flex;
			align-items: center;
			margin-top: 30px;

			.btn {
				min-width: 110px;
				height: 42px;
				line-height: 42px;
				text-align: center;
				border-radius: 100px;
				font-size: 16px;
				font-family: PingFang SC-Medium, PingFang SC;
				box-sizing: border-box;
				margin-right: 24px;
				cursor: pointer;

				&:last-child {
					margin-right: 0;
				}

			}

			.cancel {
				border: 2px solid var(--border-color-4);
				color: var(--color-38);
				background: var(--bg-51);
			}

			.confirm {
				background: var(--bg-13);
				box-shadow: inset 0px 4px 4px 0px varBB(--box-shadow-color-1);
				border-color: transparent;
				color: var(--color-7);
				font-weight: 600;
			}
		}

	}

	// PC
	@media screen and (min-width: 768px) {

		.page-wrap {
			width: 100%;
			padding-top: 70px;
			box-sizing: border-box;

			.content {
				width: 100%;
				min-height: calc(100vh - 70px) !important;
				height: calc(100vh - 70px) !important;
				overflow-y: auto;
				background: var(--bg-3);
				padding: 30px;
				box-sizing: border-box;

				.user-info {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					padding: 30px;
					margin-top: 0;
					box-sizing: border-box;

					.user-info-cont {
						flex: 1;
						height: 80px;

						.avatar-wrap {
							width: 80px;
							height: 80px;
							display: flex;
							justify-content: center;
							align-items: center;

							.avatar {
								width: 76px;
								height: 76px;
							}
						}

						.id-info {
							height: 80px;
							justify-content: space-around;
						}
					}

					.wallet-wrap {
						flex: 2;
						display: flex;
						justify-content: flex-end;
						align-items: center;
					}

					.wallet-entry {
						min-width: 200px;
						max-width: 230px;
						height: 80px !important;
						border-radius: 15px;
						background: var(--bg-15);
					}
				}

				.VIP-entry {
					min-width: 220px !important;
					max-width: 250px;
					height: 80px;
					margin-left: 15px;
					margin-top: 0;
					border-radius: 15px;
				}
			}
		}

		.popup-cont {
			width: 315px !important;
		}
	}
</style>